import 'package:flutter/material.dart';
import 'package:flutterproject/page/announce/children/announce_detail.dart';
import 'package:flutterproject/page/main/data/notice_bean.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/extension/widget_extension.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/app_bar_common.dart';
import 'package:flutterproject/widget/image_extended.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class AnnouncePage extends StatelessWidget {
  final List<NoticeBean> list;

  const AnnouncePage({super.key, required this.list});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: Get.width,
      height: Get.height,
      color: Color(0xFFF6F6F6),
      child: Column(
        children: [
          AppBarCommon(
            title: '公告',
          ),
          20.heightBox,
          Expanded(
            child: Padding(
              padding: MarginPaddingUtil.symmetric(horizontal: 20),
              child: ListView.separated(
                padding: EdgeInsets.zero,
                shrinkWrap: true,
                separatorBuilder: (context, index) => 20.heightBox,
                itemCount: list.length,
                itemBuilder: (context, index) => Container(
                  padding: MarginPaddingUtil.fromLTRB(
                      left: 55, top: 32, right: 39, bottom: 28),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(12.sp),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Container(
                            padding: MarginPaddingUtil.fromLTRB(
                                left: 20, top: 5, right: 32, bottom: 8),
                            decoration: BoxDecoration(
                              color: Color(0xFFF6F6F6),
                              borderRadius: BorderRadius.circular(25.sp),
                            ),
                            child: TextCommon(
                              DateFormat("yyyy-MM-dd HH:mm:ss").format(
                                  DateTime.fromMillisecondsSinceEpoch(
                                      list[index].publishTime ?? 0)),
                              size: 22.sp,
                              color: Color(0xFFFF707070),
                            ),
                          ),
                          Spacer(),
                          TextCommon(
                            "查看详情",
                            size: 22.sp,
                            lineHeight: 32.sp,
                            fontWeight: FontWeight.w500,
                            color: Color(0xFFFF707070),
                          ),
                          17.widthBox,
                          ImageCommon(
                            "/icon/icon_arrow_right",
                            width: 12.width,
                            height: 20.width,
                          )
                        ],
                      ),
                      20.heightBox,
                      TextCommon(
                        list[index].title ?? "",
                        size: 28.sp,
                        lineHeight: 32.sp,
                        color: Colors.black,
                      )
                    ],
                  ),
                ).addClickEvent(() => Get.to(AnnounceDetail(
                      bean: list[index],
                    ))),
              ),
            ),
          )
        ],
      ),
    );
  }
}
